var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, o, n) {
    var i, s = arguments.length, a = s < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, o, n); else for (var r = e.length - 1; 0 <= r; r--) (i = e[r]) && (a = (s < 3 ? i(a) : 3 < s ? i(t, o, a) : i(t, o)) || a);
    return 3 < s && a && Object.defineProperty(t, o, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("HpView"), s = e("PlayerModel"), c = e("GameManager"), l = e("EditView"), d = e("JoystickCommon"), u = e("AudioManager"), p = e("GameConfig"), h = e("LoadManager"), f = cc._decorator, g = f.ccclass, m = f.property, y = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e._speedType = d.default.SpeedType.STOP, e._moveSpeed = 200, e.moveDir = cc.v2(-1, 0), 
        e.moveCan = [ l.BlockType.BLOCK, l.BlockType.BOX, l.BlockType.WATER ], e.attackDir = null, 
        e.attackCan = [ l.BlockType.BLOCK, l.BlockType.BOX ], e.offect = cc.Vec2.ZERO, e.target = null, 
        e.gameView = null, e.skeleton = null, e.bufferSkeleton = null, e.sprite = null, 
        e.slot = null, e.slotName = "shouqiang", e.animation = "", e.hpView = null, e.topNode = null, 
        e.bottomNode = null, e.model = new s.default(), e.attacking = !1, e.isStart = !1, 
        e.isPlay = !1, e;
    }
    return i(e, t), e.prototype.start = function() {}, e.prototype.load = function() {
        this.topNode = new cc.Node(), this.topNode.parent = this.gameView.top, this.topNode.setPosition(this.node.getPosition()), 
        this.bottomNode = new cc.Node(), this.bottomNode.parent = this.gameView.bottom, 
        this.bottomNode.setPosition(this.node.getPosition());
        var e = "", t = "";
        c.default.getInstance().matchType == c.MatchType.三对三 && (t = this.model.group == c.default.getInstance().model.curPlayer.group ? (e = this.model.openid == GA.Info.openId ? "texture/battle/my_hp" : "texture/battle/blue_hp", 
        "texture/battle/blue_circle") : (e = "texture/battle/red_hp", "texture/battle/red_circle")), 
        h.default.getInstance().loadSpriteFrame({
            url: e,
            sprite: this.hpView.green
        }), this.hpView.node.parent = this.topNode, t && this.gameView.appendSprite({
            url: t,
            root: this.bottomNode,
            pos: cc.v2(0, -20)
        }).then(function(e) {
            e.node.active = !0, e.node.scale = 1.3, e.node.angle = 0, e.node.zIndex = -1;
        }), this.gameView.appendSprite({
            url: "texture/battle/shadow",
            root: this.node,
            pos: cc.v2(0, -20)
        }).then(function(e) {
            e.node.active = !0, e.node.scale = .7, e.node.angle = 0, e.node.zIndex = -2;
        });
    }, e.prototype.changeAnimation = function(e) {
        var t = this;
        e.flag && (this.isPlay = !1, this.animation = ""), this.skeleton && this.skeleton.skeletonData && !this.isPlay && (e.loop ? this.animation != e.animation && (this.animation = e.animation, 
        this.skeleton.timeScale = 1, this.skeleton.setAnimation(0, e.animation, e.loop), 
        this.skeleton.setEventListener(null), this.skeleton.setCompleteListener(null), e.callback && e.callback()) : (this.isPlay = !0, 
        this.animation = "", this.skeleton.timeScale = 1, this.skeleton.setAnimation(0, e.animation, e.loop), 
        this.skeleton.setCompleteListener(function() {
            t.skeleton.setEventListener(null), t.skeleton.setCompleteListener(null), t.isPlay = !1, 
            e.callback && e.callback();
        })), e.event && this.skeleton.setEventListener(function() {
            e.event();
        }));
    }, e.prototype.attackEnd = function(e) {
        void 0 === e && this.model.IDLE;
    }, e.prototype.doHurt = function(e, t) {
        void 0 === t && cc.Vec2.ZERO;
    }, e.prototype.checkHurt = function(e, t) {
        void 0 === t && (t = cc.Vec2.ZERO);
        var o = Math.floor((1 + (Math.random() - .5) / 10) * e.ATK), t = this.model.isCri(e.CRI);
        this.gameView.appendCri(e.type, this.node.getPosition(), o, t), t ? this.model.doHurt(2 * o) : this.model.doHurt(o), 
        this.hpView.refresh(this.model.HP);
    }, e.prototype.canFinded = function() {
        return this.model.canFinded();
    }, e.prototype.canMove = function() {
        return this.model.canMove();
    }, e.prototype.canHurt = function() {
        return this.model.canHurt();
    }, e.prototype.canAttack = function() {
        return this.model.canAttack();
    }, e.prototype.canDoAttack = function() {
        return this.model.canDoAttack();
    }, e.prototype.canShowGun = function() {
        return this.model.canShowGun();
    }, e.prototype.doEle = function(t) {
        var o = this;
        !this.model.hasBuffer(s.BufferType.电击) && this.canHurt() && (this.model.addBuffer(s.BufferType.电击), 
        this.pauseMove(!0), h.default.getInstance().loadRes({
            url: "skeleton/game/hurt4/skeleton",
            type: sp.SkeletonData
        }).then(function(e) {
            o.skeleton && e instanceof sp.SkeletonData && (o.node.zIndex = 1, o.sprite && (o.sprite.node.opacity = 0), 
            o.skeleton.skeletonData = e, o.skeleton.node.setPosition(cc.Vec2.ZERO), o.changeAnimation({
                animation: "animation",
                loop: !0,
                flag: !0
            }), o.skeleton.scheduleOnce(function() {
                o.checkTarget(o) && (o.model.removeBuffer(s.BufferType.电击), o.canMove() && o.resumeMove(!0), 
                o.sprite && o.canShowGun() && (o.sprite.node.opacity = 255)), t && t();
            }, 1));
        }));
    }, e.prototype.doIce = function(o) {
        var n = this;
        !this.model.hasBuffer(s.BufferType.冰冻) && this.canHurt() && (u.default.getInstance().playAudio("冰块碎裂的声音"), 
        this.model.addBuffer(s.BufferType.冰冻), this.pauseMove(!0), this.gameView.appendSkeleton({
            url: "skeleton/game/fire冰冻枪/skeleton",
            root: this.node,
            pos: cc.v2(0, -30)
        }).then(function(e) {
            n.node.zIndex = 1, n.sprite && (n.sprite.node.opacity = 0);
            var t = e;
            t.node.scale = 1.5, t.setAnimation(0, "animation2", !1), t.scheduleOnce(function() {
                n.checkTarget(n) && (n.model.removeBuffer(s.BufferType.冰冻), n.canMove() && n.resumeMove(!0), 
                n.sprite && n.canShowGun() && (n.sprite.node.opacity = 255)), n.gameView && n.gameView.removeSkeleton(t.node), 
                o && o();
            }, 3);
        }));
    }, e.prototype.doCut = function(o) {
        var n = this;
        this.canHurt() && (u.default.getInstance().playAudio("变身音效"), this.gameView.appendSkeleton({
            url: "skeleton/game/hurt12/skeleton",
            root: this.node,
            pos: cc.Vec2.ZERO
        }).then(function(e) {
            n.node.zIndex = 1;
            var t = e;
            t.node.scale = .3, t.setAnimation(0, "animation" + GA.rand(1, 3), !1), t.scheduleOnce(function() {
                n.gameView && n.gameView.removeSkeleton(t.node), o && o();
            }, 3);
        }));
    }, e.prototype.doVenom = function(o) {
        var n = this;
        this.canHurt() && this.gameView.appendSkeleton({
            url: "skeleton/game/hurt1007/skeleton",
            root: this.node,
            pos: cc.Vec2.ZERO
        }).then(function(e) {
            n.node.zIndex = 1;
            var t = e;
            t.setAnimation(0, "animation", !1), t.setCompleteListener(function() {
                t.setCompleteListener(null), n.gameView && n.gameView.removeSkeleton(t.node), o && o();
            });
        });
    }, e.prototype.doBlow = function(e) {
        var t = this;
        !this.model.hasBuffer(s.BufferType.击飞) && this.canHurt() && (this.model.addBuffer(s.BufferType.击飞), 
        this.pauseMove(!0), this.sprite && (this.sprite.node.opacity = 0), cc.tween(this.skeleton.node).to(.3, {
            position: cc.v3(0, 280)
        }, {
            easing: "quadOut"
        }).to(.3, {
            position: cc.v3(0, -20)
        }, {
            easing: "quadOut"
        }).call(function() {
            t.checkTarget(t) && (t.model.removeBuffer(s.BufferType.击飞), t.canMove() && t.resumeMove(!0), 
            t.sprite && t.canShowGun() && (t.sprite.node.opacity = 255)), e && e();
        }).start());
    }, e.prototype.doYB = function(e) {
        var t = this;
        this.canHurt() && Math.random() < .1 && (this.model.personIdx = 1006, this.model.addBuffer(s.BufferType.月饼), 
        h.default.getInstance().loadRes({
            url: "skin/1006/skeleton",
            type: sp.SkeletonData
        }).then(function(e) {
            t.skeleton && e instanceof sp.SkeletonData && (t.sprite && (t.sprite.node.opacity = 0), 
            t.skeleton.skeletonData = e, t.skeleton.setAnimation(0, "animation", !0));
        }), this.scheduleOnce(function() {
            t.checkTarget(t) && (t.model.removeBuffer(s.BufferType.月饼), t.sprite && t.canShowGun() && (t.sprite.node.opacity = 255)), 
            e && e();
        }, 3));
    }, e.prototype.doGT = function(e) {
        var t = this;
        this.canHurt() && (this.model.addBuffer(s.BufferType.狗头), h.default.getInstance().loadRes({
            url: "skin/1009/gougouqiang",
            type: sp.SkeletonData
        }).then(function(e) {
            t.skeleton && e instanceof sp.SkeletonData && (t.sprite && (t.sprite.node.opacity = 0), 
            t.skeleton.skeletonData = e, t.skeleton.setAnimation(0, "run", !0));
        }), this.scheduleOnce(function() {
            t.checkTarget(t) && (t.model.removeBuffer(s.BufferType.狗头), t.sprite && t.canShowGun() && (t.sprite.node.opacity = 255)), 
            e && e();
        }, 10));
    }, e.prototype.doDizzy = function(t) {
        var o = this;
        this.canHurt() && (this.model.addBuffer(s.BufferType.眩晕), this.gameView.appendSkeleton({
            url: "skeleton/game/hurt1008/skeleton",
            root: this.node,
            pos: cc.v2(0, 120)
        }).then(function(e) {
            o.node.zIndex = 1;
            e.setAnimation(0, "animation", !0), o.sprite && (o.sprite.node.opacity = 0), t && t(e);
        }));
    }, e.prototype.doMedical = function(e, t, o) {
        (o = void 0 === o ? this.model : o).HP = 1 == (t = void 0 === t ? 0 : t) ? Math.min(o.MAX_HP, o.HP + e) : Math.min(o.MAX_HP, o.HP + Math.round(e / 100 * o.MAX_HP)), 
        this.hpView.value = o.HP;
    }, e.prototype.doBuffer = function(e) {
        var t = this;
        switch (e.type) {
          case s.BufferType.加血:
            this.doMedical(e.buf), this.gameView.appendSkeleton({
                url: "buffer/获得/skeleton",
                root: this.node,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                e && (e.node.color = cc.Color.GREEN, e.node.active = !0, e.setAnimation(0, "animation", !1), 
                e.setCompleteListener(function() {
                    e.setCompleteListener(null), t.gameView.removeSkeleton(e.node);
                }));
            });
            break;

          case s.BufferType.加攻:
            this.bufferSkeleton || this.gameView.appendSkeleton({
                url: "buffer/爆发/skeleton",
                root: this.node,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                e && (t.bufferSkeleton = e, t.bufferSkeleton.node.zIndex = -1, t.bufferSkeleton.node.setPosition(t.skeleton.node.getPosition()), 
                t.bufferSkeleton.setAnimation(0, "animation", !0));
            }), this.model.ATK = this.model.ATK_ORG + Math.round(e.buf / 100 * this.model.ATK_ORG), 
            this.unschedule(this.removeAtkBuffer), this.scheduleOnce(this.removeAtkBuffer, e.time), 
            this.gameView.appendSkeleton({
                url: "buffer/获得/skeleton",
                root: this.node,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                e && (e.node.color = cc.Color.ORANGE, e.node.active = !0, e.setAnimation(0, "animation", !1), 
                e.setCompleteListener(function() {
                    e.setCompleteListener(null), t.gameView.removeSkeleton(e.node);
                }));
            });
            break;

          case s.BufferType.加速:
            this.model.SPE = this.model.SPE_ORG + Math.round(e.buf / 100 * this.model.SPE_ORG), 
            this.model.addBuffer(e.type), this.unschedule(this.removeSpeBuffer), this.scheduleOnce(this.removeSpeBuffer, e.time), 
            this.gameView.appendSkeleton({
                url: "buffer/获得/skeleton",
                root: this.node,
                pos: cc.Vec2.ZERO
            }).then(function(e) {
                e && (e.node.color = cc.Color.CYAN, e.node.active = !0, e.setAnimation(0, "animation", !1), 
                e.setCompleteListener(function() {
                    e.setCompleteListener(null), t.gameView.removeSkeleton(e.node);
                }));
            });
        }
    }, e.prototype.removeAtkBuffer = function() {
        this.model.ATK = this.model.ATK_ORG, this.bufferSkeleton && this.gameView.removeSkeleton(this.bufferSkeleton.node), 
        this.bufferSkeleton = null, this.model.removeBuffer(s.BufferType.加攻);
    }, e.prototype.removeSpeBuffer = function() {
        this.model.SPE = this.model.SPE_ORG, p.GC.isEquipEfffect && -1 < this.model.backEquipIdx || this.model.removeBuffer(s.BufferType.加速);
    }, e.prototype.move = function() {
        var e = this.moveDir.mul(this._moveSpeed / 60).add(this.offect.mul(1 / 60)), e = this.node.getPosition().add(e);
        e.equals(this.node.getPosition()) || (this.node.setPosition(this.check(e)), this.node.zIndex = 2 * -this.gameView.astar.getGirdY(this.node.y) + 1), 
        this.model.hasBuffer(s.BufferType.加速) ? this.node.group = "role" : this.node.group = "default";
    }, e.prototype.pauseMove = function(e) {
        (e = void 0 === e ? !1 : e) && this.canMove() && (this.attacking = !1), this.offect = cc.Vec2.ZERO, 
        this._speedType = d.default.SpeedType.STOP;
    }, e.prototype.resumeMove = function(e) {
        (e = void 0 === e ? !1 : e) && !this.canMove() && (this.attacking = !0), this.offect = cc.Vec2.ZERO, 
        this._speedType = d.default.SpeedType.NORMAL;
    }, e.prototype.getRect = function(e, t, o) {
        void 0 === o && (o = 0);
        var n = Math.min(e.x, t.x) - o, i = Math.max(e.x, t.x) + o, s = Math.min(e.y, t.y) - o, o = Math.max(e.y, t.y) + o;
        return cc.rect(n, s, i - n, o - s);
    }, e.prototype.check = function(e) {
        var t = this, o = Math.abs((this.node.width - this.gameView.map.width) / 2), n = Math.abs((this.node.height - this.gameView.map.height) / 2);
        e.x > o ? e.x = o : e.x < -o && (e.x = -o), e.y > n ? e.y = n : e.y < -n && (e.y = -n);
        var i = 0, s = this.node.getPosition(), o = cc.v2(e.x, this.node.y), n = cc.v2(this.node.x, e.y);
        return this.gameView.astar.retrieve(this.getRect(s, o, 20)).some(function(e) {
            return -1 < t.moveCan.indexOf(e.type);
        }) || i++, this.gameView.astar.retrieve(this.getRect(s, n, 20)).some(function(e) {
            return -1 < t.moveCan.indexOf(e.type);
        }) || (i += 2), 0 == i ? e = s : 1 == i ? e.y = this.node.y : 2 == i ? e.x = this.node.x : this.gameView.astar.retrieve(this.getRect(s, e, 20)).some(function(e) {
            return -1 < t.moveCan.indexOf(e.type);
        }) && (o.sub(s).mag() > n.sub(s).mag() ? e.y = this.node.y : e.x = this.node.x), 
        e;
    }, e.prototype.checkVisual = function(e) {
        return this.model.hasBuffer(s.BufferType.隐藏中) && Math.abs(e.x - this.node.x) + Math.abs(e.y - this.node.y) <= 80 * c.default.getInstance().fieldgird;
    }, e.prototype.checkTarget = function(e) {
        return e && e.model && !e.model.isDead();
    }, e.prototype.findTargets = function() {
        var o = this;
        return this.gameView.targets.filter(function(e) {
            return o.checkTarget(e) && e.canHurt() && e.canFinded() && e.model.group != o.model.group;
        }).sort(function(e, t) {
            return e.node.position.sub(o.node.position).mag() - t.node.position.sub(o.node.position).mag();
        });
    }, e.prototype.getDir = function(e) {
        return void 0 === e && (e = this.target), this.checkTarget(e) ? cc.v2(e.node.getPosition().sub(this.node.getPosition()).normalizeSelf()) : this.moveDir;
    }, e.prototype.getOffect = function(e, t) {
        return void 0 === e && (e = 0), void 0 === t && (t = 0), this.sprite ? 1008 == this.model.gunIdx ? this.node.convertToNodeSpaceAR(this.sprite.node.convertToWorldSpaceAR(cc.v2(-45 + e, t))) : this.node.convertToNodeSpaceAR(this.sprite.node.convertToWorldSpaceAR(cc.v2(-90 + e, 90 + t))) : cc.Vec2.ZERO;
    }, e.prototype.updateDir = function(e) {
        var t;
        void 0 === e && (e = this.moveDir), this.skeleton && (0 < e.x ? this.skeleton.node.scaleX = -.5 : e.x < 0 && (this.skeleton.node.scaleX = .5)), 
        this.sprite && (t = 0, 1008 != this.model.gunIdx && (t = 33), 0 < e.x ? (this.sprite.node.scaleX = -.5, 
        this.sprite.node.angle = -t + cc.misc.radiansToDegrees(Math.atan2(e.y, e.x))) : e.x < 0 && (this.sprite.node.scaleX = .5, 
        this.sprite.node.angle = -180 + t + cc.misc.radiansToDegrees(Math.atan2(e.y, e.x))));
    }, a([ m(sp.Skeleton) ], e.prototype, "skeleton", void 0), a([ m(r.default) ], e.prototype, "hpView", void 0), 
    a([ g ], e);
}(cc.Component);

n.default = y;